import com.beans.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/4/4 11:37
 * 更加easy的存取Bean的两种方式（注解）
 *  1.使用5大类注解
 *       @Service
 *       @Repository
 *       @Component
 *       @Controller
 *       @Configuration
 *  2.使用Bean方法注解 需要配合5大类注解使用
 *     要先扫描到这个类，才能从类中找到方法注解
 *       @5大类 + @Bean
 */
public class App {

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-config.xml");
        UserService user1 = applicationContext.getBean("userService", UserService.class);
        UserComponent user2 = applicationContext.getBean("userComponent", UserComponent.class);
        UserController user3 = applicationContext.getBean("userController", UserController.class);
        UserConfiguration user4 = applicationContext.getBean("userConfiguration", UserConfiguration.class);
        UserRepository user5 = applicationContext.getBean("userRepository", UserRepository.class);
        user1.sayHello();
        user2.sayHello();
        user3.sayHello();
        user4.sayHello();
        user5.sayHello();
        User user = (User)applicationContext.getBean("getUser",User.class);
        System.out.println(user);

    }
}
